package com.softtown.modules.sys.controller;

import com.softtown.modules.sys.webSocket.WebSocket;
import io.swagger.annotations.Api;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * webSocket调用类
 *
 * @author Dingyayong
 * @version v1.0
 * @create 2019-07-05 10:06
 **/
@RestController
@RequestMapping("/api")
@Api(tags = "webSocket")
public class WebSocketController {

    @Resource
    private WebSocket webSocket;

    @GetMapping("/sendAllWebSocket")
    public String test() {
        String text="你们好！这是websocket群体发送！";
        webSocket.sendAllMessage(text);
        return text;
    }

    @GetMapping("/sendOneWebSocket/{userName}")
    public String sendOneWebSocket(@PathVariable("userName") String userName) {
        String text=userName+" 你好！ 这是websocket单人发送！";
        webSocket.sendOneMessage(userName,text);
        return text;
    }
}

